package com.hxzy.action;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.google.gson.Gson;
import com.hxzy.entity.Team;
import com.hxzy.entity.User;
import com.hxzy.service.TeamService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class BaseTeamAction extends ActionSupport {

	private static final long serialVersionUID = 3809248650639436301L;

	private TeamService teamService;
	public String list() throws Exception {
		// TODO Auto-generated method stub
		List<Team> teamList=teamService.list(1);
		Gson gson=new Gson();
		String teamJson=gson.toJson(teamList);
		HttpServletResponse response=ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		response.setHeader("Content-Type", "application/json");
		response.getWriter().write(teamJson);
		return null;
	}
	
	public String myTeam() throws Exception{
		User sessionUser=(User) ActionContext.getContext().getSession().get("userLogin");
		List<Team> myTeamList=teamService.myTeam(sessionUser.getId());
		Gson gson=new Gson();
		String myTeamJson=gson.toJson(myTeamList);
		HttpServletResponse response=ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		response.setHeader("Content-Type", "application/json");
		response.getWriter().write(myTeamJson);
		return null;
	}

    public TeamService getTeamService() {
        return teamService;
    }

    public void setTeamService(TeamService teamService) {
        this.teamService = teamService;
    }

  
	
	
}
